//
//  JFDBUtil.m
//  JFore
//
//  Created by Synergy_iMac1 on 12-12-12.
//  Copyright (c) 2012年 Synergyinfo. All rights reserved.
//

#import "JFDBUtil.h"

#define JFDB_UTIL_MAX_PROPERTY_TYPE_LEN 255

void JFLog(NSString *format,...)
{
#ifdef JF_DATABASE_LOG_ENABLE
    va_list args;
    va_start(args, format);
    NSLogv(format,args);
    va_end(args);
#endif
}

@implementation JFDBUtil

+ (JFDBColumnType)getProperyType:(objc_property_t)propery
{
    const char* propertyAttributes = property_getAttributes(propery);
    int i = 0;
    char propertyType[JFDB_UTIL_MAX_PROPERTY_TYPE_LEN];
    while (propertyAttributes[i] != '\0' && propertyAttributes[i] != ',')
    {
        propertyType[i] = propertyAttributes[i];
        i++;
    }
    propertyType[i] = '\0';
    if (strcmp(propertyType,"T@\"NSString\"") == 0)
    {
        return kJFDBColumnTypeString;
    }
    else if (strcmp(propertyType,"Ti") == 0)
    {
        return kJFDBColumnTypeInt;
    }
    else if (strcmp(propertyType,"Td") == 0)
    {
        return kJFDBColumnTypeFloat;
    }
    else
    {
        return kJFDBColumnTypeInvalid;
    }
}

+ (NSString*)getProperyTypeString:(objc_property_t)propery
{
    switch ([self getProperyType:propery])
    {
        case kJFDBColumnTypeString:
            return @"text";
        case kJFDBColumnTypeInt:
            return @"int";
        case kJFDBColumnTypeFloat:
            return @"double";
        default:
            return nil;
    }
}

@end
